package com.woniuxy.oldobject.service.impl;

import com.woniuxy.oldobject.dao.ActivityDao;
import com.woniuxy.oldobject.entity.Activity;
import com.woniuxy.oldobject.entity.ActivityRecord;
import com.woniuxy.oldobject.entity.ResponseEntity;
import com.woniuxy.oldobject.dto.SearchDto;
import com.woniuxy.oldobject.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired(required = false)
    ActivityDao activityDao;
//return new ResponseEntity(200,"查询成功",)

//    查询所有活动
    @Override
    public ResponseEntity findAll() {
        System.out.println("aa");
        List<Activity> activityList = activityDao.selectAll();
//        List<Activity> activityList  = dataList.subList(0,5);
        if(activityList.size()>1){
            return new ResponseEntity(200,"查询成功",activityList);
        }else{
            return ResponseEntity.ERROR;
        }
    }

//    根据活动类型查询活动记录
    @Override
    public ResponseEntity activityManageByType(String activityType) {
        List<ActivityRecord> activityList = activityDao.selectActivityManageByType(activityType);
        if(activityList.size()>1){
            return new ResponseEntity(200,"查询成功",activityList);
        }else{
            return ResponseEntity.ERROR;
        }
    }

//    新增一个活动记录
    @Override
    public ResponseEntity addOneActivityRecord(ActivityRecord activityRecord) {
        int i = activityDao.insert(activityRecord);
        if(i==1){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public ResponseEntity deleteOneActivityRecordById(int id) {
        int i = activityDao.deleteOneActivityRecordById(id);
        if(i==1){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public ResponseEntity changeOneActivityRecord(ActivityRecord activityRecord) {
        int i = activityDao.updateById(activityRecord);
        if(i==1){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
    }


    @Override
    public ResponseEntity searchActivityRecord(SearchDto searchDto) {
        List<ActivityRecord> activityList = activityDao.selectActivityRecord(searchDto.getElderName(), searchDto.getActivityType(), searchDto.getActivityName());
        if(activityList.size()>=1){
            return new ResponseEntity(200,"查询成功",activityList);
        }else{
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public ResponseEntity searchActivity(SearchDto searchDto) {
        List<Activity> activityList = activityDao.selectActivity(searchDto.getActivityType(), searchDto.getActivityName());
        if(activityList.size()>=1){
            return new ResponseEntity(200,"查询成功",activityList);
        }else{
            return ResponseEntity.ERROR;
        }
    }
}
